$(function(){
	$('#tt').datagrid({
		url:'/monitorConfig/getMonitorConfigListPage'
	});
	
});

function doAdd(){
	$('#addForm').form('clear');
	$('#addWin').window('open');
}

function doEdit(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$('#itemKeyId').val(record.itemKey);
	$('#itemValueId').val(record.itemValue);
	$('#remarkId').val(record.remark);
	$('#idId').val(record.id);
	
	$('#addWin').window('open');
}

function doDel(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$.messager.confirm('提示', '你确定要删除吗', function(opt){
		if (opt){
			$.ajax({
				url: '/monitorConfig/deleteMonitorConfig',
				type: 'POST',
				data : {
		            id:record.id
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "删除成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});	
	
}

function doSearch(){
	var itemKey=$('#sitemKeyId').val();
	
	$('#tt').datagrid({
		url:'/monitorConfig/getMonitorConfigListPage',
		queryParams:{
			itemKey:itemKey
		}
	});
	$('#tt').datagrid('unselectAll');
}

function save(){
	var id=$('#idId').val();
	var url='/monitorConfig/updateMonitorConfig';
	if(id==null||id==''){
		url='/monitorConfig/saveMonitorConfig';
	}
	
	$('#addForm').form('submit',{
		url : url,
		onSubmit : function() {
			var flag = $(this).form('validate');
			if (!flag) {
				return flag;
			}
			showProcess(true, market.content.title, market.content.submitting);
			return true;
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			console.log(data);
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$('#tt').datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
	
}

function cancel(){
	$('#addWin').window('close');
}

